<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<%@include file="/header.jsp" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>字典值页面</title>
<script type="text/javascript">
function refGrid(){
	$('#datagridtable').datagrid("clearChecked");
	$('#datagridtable').datagrid("options").url='${base}sysCode/codeList?'+$("form").serialize();
	$('#datagridtable').datagrid("load");  
}

  $(function(){
	  $('#dl').datalist({
		    url: '${base}sysCode/codeSetList',
		    queryParams:{codeSet:$("#codeSetSearch").textbox('getValue')},
		    lines: true,
		    onSelect:function(rowIndex, rowData){
                $("#csId").val(rowData.value);
                refGrid();
	  },onLoadSuccess:function(data){
		//默认选中第一条
		  if(data&&data.rows)
			  $('#dl').datalist("selectRow",0);
	  }
	});
	   
	  $("#codeSetSearch").textbox({onClickButton:function(){
		  $('#dl').datalist("clearChecked");
		  var sText=$("#codeSetSearch").textbox('getValue');
		  $('#dl').datalist({
			    url: '${base}sysCode/codeSetList',queryParams:{codeSet:sText}});
	}}); 
	  
	  $("#searchbtn").click(function(){refGrid();});
	  
	  $('#datagridtable').datagrid({    
		    singleSelect:false,
		    collapsible:false,
		    url:'',//'${base}sysCode/codeList?'+$("form").serialize(),
		    method:'post',
		    pagination:true,
		    toolbar:'#toolbar',
			pageSize:20,
			multiSort:true,
			rownumbers:true,
			border:false,
			animate:true,
			idField:'id',
			autoRowHeight:false,
			fitColumns: true,
		    columns:[[    
		        {field:'id',checkbox:true},    
		        {field:'itemName',title:'字典值名称',width:150,sortable:true},    
		        {field:'itemValue',title:'字典值',width:100,sortable:true},
		        {field:'codeStatus',title:'状态',width:100,sortable:true,formatter:function(value,row,index){
			        var data=${SysCodeStatus};
			        for(var i=0;i<data.length;i++){
			        	if(data[i].itemValue==value&&data[i].itemValue!='')
				        	return data[i].itemName;  
 				        }
			        }},
		        {field:'orderNo',title:'排序',width:120,sortable:true},
		        {field:'remark',title:'描述',width:300,sortable:true}
		    ]]    
		});
	  $("#addBtn").click(function(){
		  if($("#csId").val())
			  myDialog({title:"增加字典值",src:"${base}sysCode/addPage?csId="+$("#csId").val(),width:750,height:300,callBack:refGrid});
			  else
			 myAlert("错误信息","请选择左侧 字典集！","e");	  
      });
      $("#editBtn").click(function(){
    	  var selOpts =$('#datagridtable').treegrid("getChecked");
			if(selOpts.length==0||selOpts.length>1)
				myAlert("错误信息","请选择一条记录！","e");
			else
			  myDialog({title:"修改字典值",src:"${base}sysCode/editPage?id="+selOpts[0].id,width:750,height:300,callBack:refGrid});
      });
      $("#delBtn").click(function(){
    	  var selOpts =$('#datagridtable').datagrid("getChecked");
			if(selOpts.length==0){
				myAlert("错误信息","请选择需要删除的记录！","e");
				return;
				}
			ids=[];
			$.each(selOpts,function(i,v){
				     ids.push(v.id);
				});
			myConfirm("提示信息","确定删除选中的数据吗?",function(r){
                   if(r){
                  	 myAjax({url:"${base}sysCode/delCode",data:{"ids":ids},  
                      	 success:function(data){
                                if(data.error=='0')
                              	      refGrid();
                                else
                              	  myAlert("错误信息",data.msg,"e");   
                      	 }
                  	 }); 
                }
			});
      });
      $("#detailBtn").click(function(){
    	  var selOpts =$('#datagridtable').datagrid("getChecked");
			if(selOpts.length==0||selOpts.length>1)
				myAlert("错误信息","请选择一条记录！","e");
			else
			  myDialog({title:"查看字典值",src:"${base}sysCode/detailPage?id="+selOpts[0].id,width:750,height:300,
				  callBack:function(){
				  $('#datagridtable').datagrid("clearChecked");}});
      });
});
</script>
</head>
<body fit="true">
<div class="easyui-layout" fit="true">
		<div data-options="region:'west',split:false,border:false,title:'字典集列表'"   style="width:200px;">
		       <table style="height:100%;width:100%;" cellpadding="1" cellspacing="0">
		       <tr height="30"><td valign="middle">
		       <input id="codeSetSearch" class="easyui-textbox" 
		       data-options="buttonText:'',buttonIcon:'icon-search',prompt:'字典集搜索'" 
		       style="width:198px;height:24px;"/>
                </td></tr>
		       <tr><td>
		       <div id="dl" fit="true"></div>
            </td></tr>
		       </table>
		</div>
		<div data-options="region:'center',border:false">
   <div id="toolbar">
    <div class="toolbar_searchcondition">
   <form class="easyui-form" action="${base}sysCodeSet/codeList"  method="post">
      <input id="csId" name="params['csId']" type="hidden"/>
	  字典名称: <input class="easyui-textbox" name="params['itemName']" type="text"/>&nbsp;
	  字典值: <input class="easyui-textbox"  name="params['itemValue']" type="text"/>&nbsp;
	  状态: <input class="easyui-combobox"  name="params['codeStatus']" type="text" data-options='valueField:"itemValue",textField:"itemName",data:${SysCodeStatus},editable:false'/>&nbsp;
		   <a href="#" class="easyui-linkbutton searchbtn" iconCls="icon-search" id="searchbtn">查询</a>
		</form>
	</div>
	<div class="toolbar_btns">
	    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" id="addBtn">添加</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" id="editBtn">编辑</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" id="delBtn">删除</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" id="detailBtn">查看</a>
	</div>
   </div>
	  <table id="datagridtable"  style="width:1200px;height:500px" fit="true"></table>
		</div>
	</div>
</body>
</html>